//
//  SEExamineRecordBaseViewModel.swift
//  SmartEyeForPatient
//
//  Created by qdsg on 2021/8/10.
//

import UIKit

class SEExamineRecordBaseViewModel: NSObject {
    
    var model = SEExamineRecordModel()

    required convenience init(model: SEExamineRecordModel) {
        self.init()
        self.model = model
    }

    var resultDescription: String {
        ""
    }

    var showLeft: Bool {
        model.checkEyePart != .right
    }

    var showRight: Bool {
        model.checkEyePart != .left
    }

    var showImages: Bool {
        model.imageUrls.count > 0
    }

    func examineImgCellModel(index: Int) -> SEExamineRecordImageCellModel {
        guard showImages, index < model.imageUrls.count else {
            return SEExamineRecordImageCellModel()
        }
        return SEExamineRecordImageCellModel(imgUrlStr: model.imageUrls[index])
    }

    func examineRecordData(index: Int) -> SEExamineRecordData {
        guard let data = model.dataDTO.last, index < data.count else {
            return SEExamineRecordData()
        }
        return data[index]
    }

    var numberOfSections: Int {
        return (model.dataDTO.last?.count == 2) ? 3 : 0
    }

    func heightForRow(indexPath: IndexPath) -> CGFloat {
        switch indexPath.section {
        case 0, 1: return 150
        case 2: return 160
        default: return 0
        }
    }

    func numberOfRowInSection(section: Int) -> Int {
        switch section {
        case 0: return showLeft ? 1 : 0
        case 1: return showRight ? 1 : 0
        case 2: return model.imageUrls.count
        default: return 0
        }
    }

    func heightForHeader(section: Int) -> CGFloat {
        switch section {
        case 0: return showLeft ? 35.0 : 0
        case 1: return showRight ? 35.0 : 0
        case 2: return showImages ? 35.0 : 0
        default: return 0
        }
    }

    func titleForHeaderInSection(section: Int) -> String {
        switch section {
        case 0: return showLeft ? "左眼" : ""
        case 1: return showRight ? "右眼" : ""
        case 2: return showImages ? "图像" : ""
        default: return ""
        }
    }
    
}
